home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
Think Files.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-01-27
|
5KB
|
248 lines
/*********************************************************************
* *
* ThinkFiles - Extract ".c" files from a Think C 4.02 project file *
* *
* 10/15/90 *
* This hack is so terrible that I'm not putting my name on it, *
* the only saving grace is that it seems to work. *
* *
* When debugging, set the project type to application, *
* and add the ANSI project. *
* *
* When all your bugs are out, 'undef' DEBUG, set the project *
* type to Code Resource, with type = ACMD, name = <the name *
* of the function>, file type to 'AEXT', and the purgeable *
* flag set to true. *
* *
* Also, you need to remove the ANSI project from the ACMD *
* project and replace it with the ANSI-A4 project if you use *
* any functions in ANSI, such as strlen. *
* *
* If you are not using THINK C, I'm not quite sure what you *
* should do. :-) *
* *
*********************************************************************/
#include <MacHeaders>
#undef DEBUG
#ifndef DEBUG
#include <SetUpA4.h>
#endif DEBUG
#include <stdio.h>
#include <string.h>
int condensed = FALSE; /* fool dir.c */
char *
#ifdef DEBUG
dummy(inStr)
#else DEBUG
main(inStr)
#endif DEBUG
char *inStr;
{
OSErr rf;
int i, j, len, num, volLen;
char str[256], str2[256];
Handle hand;
char *ptr, *dirPtr;
size_t sz;
Point dlg_org;
SFTypeList theTypeList;
SFReply theReply;
char pathName[256];
char *outStr;
char *ptrs[100];
int soFar = 0;
#ifndef DEBUG
RememberA0();
SetUpA4();
#endif DEBUG
/* set the pointer block to something real large */
outStr = NewPtr(10000L);
memcpy(outStr,inStr,GetPtrSize(inStr));
DisposPtr(inStr);
inStr = outStr;
SetPt(&dlg_org,100,100);
theTypeList[0] = 'PROJ';
SFGetFile(dlg_org, "\pWhich Proj:", 0L, 1, theTypeList,0L,&theReply);
if (!theReply.good)
{
SysBeep(1);
#ifndef DEBUG
RestoreA4();
#endif DEBUG
return FALSE;
}
pathName[0] = 0;
PathNameFromWD((long)theReply.vRefNum,pathName);
ptoc(pathName);
for (dirPtr = pathName + strlen(pathName); *--dirPtr != ':';);
dirPtr++;
*dirPtr = 0;
SetVol("",theReply.vRefNum);
if ((rf = OpenResFile(theReply.fName)) <= 0)
{
SysBeep(1);
#ifndef DEBUG
RestoreA4();
#endif DEBUG
return(FALSE);
}
num = Count1Resources('ZONE');
for (i = 1; i <= num; i++)
{
if (!(hand = Get1IndResource('ZONE',i)))
{
SysBeep(1);
continue;
}
HLock(hand);
ptr = *hand;
sz = GetHandleSize(hand);
for (ptr = *hand; ptr < (*hand + sz); ptr++)
{
if (!strncmp(ptr, ".c", 2L))
{
for (j = 0; j < 256; j++)
{
if (*(ptr - j + 1) == j)
{
pStrcpy(str2,ptr - j + 1);
ptoc(str2);
/* see if we need to add path */
for (len = strlen(str2), j=0; j < len; j++)
{
if (str2[j] == ':') break;
}
if (j == len)
{
strcpy(dirPtr,str2);
strcpy(str2,pathName);
*dirPtr = 0;
}
/* now check to make sure we don't already have this one */
len = strlen(str2);
for (j = 0; j < soFar; j++)
{
if (!strncmp(str2,ptrs[j], (long)len)) break;
}
if (j != soFar) break;
#ifdef DEBUG
strcat(str2,"\n");
#else
strcat(str2,"\r");
#endif DEBUG
ptrs[soFar++] = outStr;
strcpy(outStr,str2);
outStr += strlen(str2);
break;
}
}
}
}
HUnlock(hand);
ReleaseResource(hand);
}
*outStr++ = 0;
SetPtrSize(inStr,outStr - inStr);
#ifndef DEBUG
RestoreA4();
#endif DEBUG
CloseResFile(rf);
return(inStr);
}
ctop(str)
char *str;
{
size_t len;
len = strlen(str);
bcopy(str + 1, str, len);
str[0] = (char)len;
}
ptoc(str)
char *str;
{
size_t len = str[0];
bcopy(str, str+1, len);
str[len] = 0;
}
pStrcat(s1,s2)
char *s1,*s2;
{
strncpy(s1 + *s1 + 1,s2+1,(size_t)*s2);
*s1 += *s2;
}
pStrcpy(s1,s2)
char *s1, *s2;
{
s1[0] = s2[0];
strncpy(s1+1,s2+1,(size_t)s2[0]);
}
pStrcmp(s1,s2)
char *s1, *s2;
{
size_t len = s1[0];
size_t res;
if (s2[0] < len) len = s2[0];
if (res = strncmp(s1+1,s2+1,len))
return(res);
return((int)(s1[0] - s2[0]));
}
bcopy(s1,s2,sz)
char *s1,*s2;
size_t sz;
{
memmove(s1,s2,sz);
}
#ifdef DEBUG
main()
{
char *ptr;
printf("Hello\n");
ptr = NewPtr(2L);
ptr = dummy(ptr);
printf("Return was:\n%s",ptr);
ptr = NewPtr(2L);
ptr = dummy(ptr);
printf("Return was:\n%s",ptr);
ptr = NewPtr(2L);
ptr = dummy(ptr);
printf("Return was:\n%s",ptr);
}
#endif DEBUG